package com.timothy.android;

import java.util.ArrayList;
import java.util.List;

import com.timothy.question.Choice;

import android.content.Context;
import android.graphics.Color;
import android.graphics.drawable.Drawable;
import android.util.Log;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.Button;
import android.widget.GridView;

public class ButtonAdapter extends BaseAdapter {
	private static final String LOG_TAG = "ButtonAdapter";
	
	private Context mContext = null;
	   // references to our images
    private List<Button> btnList = new ArrayList<Button>();
    private List<Choice> choices = null;
    private LayoutSettingButton btnSetting = null;
//    private Drawable btnDrawable = null;
    
    public ButtonAdapter(Context c) {
        mContext = c;
        for(Choice choice:choices){
        	Button btn = new Button(c);
        	btn.setText(choice.getContent());
        	btn.setBackgroundColor(Color.GREEN);
    		btnList.add(btn);        	
        }
    }
    
    public ButtonAdapter(Context c,List<Choice> choices,LayoutSettingButton btnSetting) {
        this.mContext = c;
        this.choices = choices;
        this.btnSetting = btnSetting;
        
//        this.btnDrawable = btnDrawable;
        for(Choice choice:choices){
        	Button btn = new Button(c);
        	btn.setText(choice.getContent());
        	btn.setHeight(btn.getHeight());
        	btn.setWidth(btn.getWidth());
        	btn.setBackgroundDrawable(btnSetting.getBtnDrawable());
        	btn.setClickable(false);
        	btn.setFocusable(false);
    		btnList.add(btn);        	
        }
    }
    
	@Override
	public int getCount() {
		// TODO Auto-generated method stub
		return btnList.size();
	}

	@Override
	public Object getItem(int position) {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public long getItemId(int position) {
		// TODO Auto-generated method stub
		return 0;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		Button button;
        if (convertView == null) {  // if it's not recycled, initialize some attributes
            button = new Button(mContext);
            Log.i(LOG_TAG,"btnSetting.getHeight():" + btnSetting.getHeight());
            Log.i(LOG_TAG,"btnSetting.getWidth():" + btnSetting.getWidth());
            button.setLayoutParams(new GridView.LayoutParams(btnSetting.getHeight(), btnSetting.getWidth()));
            button.setPadding(2,2,2,2);
        } else {
            button = (Button) convertView;
        }

        button = btnList.get(position);
        return button;
	}

	public List<Choice> getChoices() {
		return choices;
	}

	public void setChoices(List<Choice> choices) {
		this.choices = choices;
	}
	
	

}
